package com.tanhua.server.service;

import com.alibaba.dubbo.config.annotation.Reference;
import com.tanhua.dubbo.server.api.RecommendUserApi;
import com.tanhua.dubbo.server.pojo.RecommendUser;
import com.tanhua.dubbo.server.vo.PageInfo;
import com.tanhua.server.vo.TodayBest;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: cloudy
 * @Description:
 * @Date: Created in 22:13 2021/1/4
 * @ModifiedBy:
 */
@Service
public class RecommendUserService {

    @Reference(version = "1.0.0")
    private RecommendUserApi recommendUserApi;

    public TodayBest queryTodayBest(Long userId) {
        RecommendUser recommendUser = recommendUserApi.queryWithMaxScore(userId);
        if (recommendUser == null) {
            return null;
        }
        //TodayBest通过recommendUser封装成一个todayBest对象
        TodayBest todayBest = new TodayBest();
        todayBest.setId(recommendUser.getUserId());

        double score = Math.floor(recommendUser.getScore());
        todayBest.setFateValue(Double.valueOf(score).longValue());
        return todayBest;
    }

    /**
     * 查询mongodb中的recommendUSerList,并将其赋值给pageInfo
     * @param page
     * @param pagesize
     * @return
     */
    public PageInfo<RecommendUser> queryRecommendUserList(Long userId, Integer page, Integer pagesize) {
        return recommendUserApi.queryPageInfo(userId, page, pagesize);
    }

    public double queryScore(Long userId, Long toUserId) {
        return this.recommendUserApi.queryScore(userId,toUserId);
    }
}
